# -*- coding:utf-8 -*-
from flask import Blueprint, redirect, session, request, url_for

admin_blu = Blueprint("admin", __name__, url_prefix="/admin")

from . import views


@admin_blu.before_request
def check_admin():
    """检查当前用户是否为管理员"""
    if request.url.split("?")[0].endswith(url_for(f"{admin_blu.url_prefix[1:]}.create_super_user")):
        pass
    else:
        isAdmin = session.get("isAdmin")
        if (not isAdmin) and (not request.url.endswith(url_for(f"{admin_blu.url_prefix[1:]}.login"))):
            return redirect("/")
